console.log("课题页面")
var roleMap = {
    0: "管理员",
    1: "院士",
    2: "人才",
    3: "单位",
    4: "主管部门",
    5: "专家"
};
var statusMap = {
    1: "启用",
    2: "禁用"
};

var categoryMap = {
    1: "创意设计",
    2: "基础部件",
    3: "整机套装",
    4: "应用配套"
};
var catetorySecondMap = {};

layui.use(['form', 'code', 'laydate', 'upload', 'layer', 'laytpl', 'element', 'laypage'], function () {
    var laydate = layui.laydate;
    form = layui.form;
    upload = layui.upload;
    layer = layui.layer;
    laytpl = layui.laytpl;
    element = layui.element;
    laypage = layui.laypage;


    layui.code();

    //初始化列表

    $(".searchBtn").click(function () {
        search();
        return false;
    });

    search();

    function setParam(param) {
        var searchName = $(".searchName").val();
        if(searchName){
            param.searchName = searchName;
        }
    }

    function search() {
        $(".organList").html("");
        var param = {pageNum: 1, pageSize: 10};
        setParam(param);
        AJAX.post(cgiMain.organInfoPageQuery,
            param,
            function (res) {

                if (res.code == '0000') {
                    $(".organList").data("organList", res.result.list);
                    var tpl = $("#organTpl").html();
                    var resultPage = res.result;
                    for (var i = 0; i < resultPage.list.length; i++) {

                        var item = resultPage.list[i];

                        laytpl(tpl).render(item, function (html) {
                            $(".organList").append(html);
                        });
                    }
                    //执行一个laypage实例
                    laypage.render({
                        elem: 'pagination'
                        , limit: 10
                        , count: resultPage.totalCount
                        , limits: [10]
                        , theme: '#1E9FFF'
                        , layout: ['prev', 'page', 'next', 'limit', 'count']
                        , jump: function (obj, first) {
                            if (first == true) {
                                return;
                            }
                            $(".organList").html("");
                            nextPage(obj.curr, 10);

                        }
                    });
                    $(".organList").on("mousemove",'.descTd',function (elem) {
                        $(elem.target).removeClass("td_cust");

                    });
                    $(".organList").on("mouseout",'.descTd',function (elem) {
                        $(elem.target).addClass("td_cust");

                    });
                    element.render(".organList");
                    form.render();
                }else{
                    $("#pagination").html("");
                }

            });
    }

    function nextPage(pageNum, pageSize) {
        var param = {pageNum: pageNum, pageSize: pageSize};
        setParam(param);
        AJAX.post(cgiMain.organInfoPageQuery,
            param,
            function (res) {

                if (res.code == '0000') {
                    $(".organList").data("organList", res.result.list);
                    var tpl = $("#organTpl").html();
                    var resultPage = res.result;
                    for (var i = 0; i < resultPage.list.length; i++) {

                        var item = resultPage.list[i];

                        laytpl(tpl).render(item, function (html) {
                            $(".organList").append(html);
                        });
                        $(".organList").on("mousemove",'.descTd',function (elem) {
                            $(elem.target).removeClass("td_cust");

                        });
                        $(".organList").on("mouseout",'.descTd',function (elem) {
                            $(elem.target).addClass("td_cust");

                        });
                    }
                    element.render(".organList");
                    form.render();
                }

            });
    }


});


